package registers;

/**
 * @author Kevin
 *
 */
public class Register 
{
	private double currentAmount;
	private int id;
	private double tax;

	public Register(int id)
	{
		currentAmount = 100.0;
		this.id = id;
	}

	/**
	 * Set the tax rate to work at
	 * @param rate the tax rate from 0.00 to 1.0
	 */
	public void setTax(double rate)
	{
		if(rate < 0.0)
		{
			return;
		}

		tax = rate;
	}

	/**
	 * Get the current amount the register holds
	 * @return the current amount
	 */
	public double getCurrentAmount()
	{
		return currentAmount;
	}

	/**
	 * Get the ID number of this register
	 * @return the ID number
	 */
	public int getID()
	{
		return id;
	}

	/**
	 * Calculate the total after tax is applied
	 * @param subtotal The subtotal before Tax
	 * @return the total amount after Tax
	 */
	public double taxCalc(double subtotal)
	{
		double total = subtotal;

		total += (total * tax);

		return total;
	}

	/**
	 * Adds the specified amount to the register and calculates the change
	 * @param charged How much is owed
	 * @param paid How much was paid
	 * @return the change due
	 */
	public double creditRegister(double charged, double paid)
	{
		double total = taxCalc(charged);
		if(total > paid || paid < 0 || total < 0)
		{
			return -1.0;
		}

		currentAmount += total;
		return (paid - total);		
	}
}
